//
//  NSString+Bool.m
//  ccyCard
//
//  Created by ileo on 14-4-8.
//  Copyright (c) 2014年 mudi. All rights reserved.
//

#import "NSString+Bool.h"

@implementation NSString (Bool)

-(BOOL)isTel{
    NSString *telRegex = @"^[1][3-8]\\d{9}$";
    NSPredicate *telTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", telRegex];
    return [telTest evaluateWithObject:self];
}

- (BOOL)isNotNil
{
    if ([self isKindOfClass:[NSNull class]] || self == nil || (id)self == [NSNull null] || [self isEqualToString:@""])
        return NO;
    return YES;
}

-(BOOL)isCode{
    NSString *codeRegex = @"\\d{4,6}";
    NSPredicate *codeTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", codeRegex];
    return [codeTest evaluateWithObject:self];
}

-(BOOL)isNumOrsASC{
    NSString *numOrBigASC = @"\\w+";
    NSPredicate *numOrBigASCTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", numOrBigASC];
    return [numOrBigASCTest evaluateWithObject:self];
}

- (NSString *)isNull
{
    BOOL isNull =  [self isNotNil];
    if (isNull == NO) {
        return @" -- ";
    }
    return self;
}

- (BOOL)isCorrectPassWord
{
    NSString * passWord= @"^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,10}$";
    NSPredicate * passWordTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",passWord];
    return [passWordTest evaluateWithObject:self];
}

- (BOOL)isNumber
{
    NSString * regex  = @"(/^[0-9]*$/)";
    NSPredicate * numberStr = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
    return [numberStr evaluateWithObject:self];
    
}
@end
